package com.max.project.graphics.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import com.max.project.graphics.dao.ContentDao;
import com.max.project.graphics.model.Content;

/**
 * 
 * 项目名称:max-project-graphics
 * 文件名称:ContentDaoImpl.java
 * 文件描述:
 * 创建人员:chenyibo
 * 创建时间:2013-1-22 下午03:04:41
 * 修改人员:chenyibo
 * 修改时间:2013-1-22 下午03:04:41
 * 修改备注:
 * @version V1.0
 */
public class ContentDaoImpl extends DaoSupport implements ContentDao
{
	
	@Override
	public int insert(Content content) throws SQLException 
	{
		int i = runner.update(
				"INSERT INTO t_project_graphics_content (name,content,creator,modifier,create_date,modify_date) VALUES (?,?,?,?,?,?)",
				content.getName(),content.getContent(),content.getCreator(),content.getModifier(),content.getCreate_date(),content.getModify_date());
		
		return i;
	}
	
	@Override
	public Content query(int id) throws SQLException 
	{
		Content content = null;
		content = (Content) runner.query(
				"select * from t_project_graphics_content where id=?",
				new BeanHandler(Content.class), id);
		
		return content;
	}

	@Override
	public List<Content> query(int pos, int len) throws SQLException 
	{
		List<Content> list = null;
	    list = (List<Content>) runner.query(
	    		"select * from t_project_graphics_content order by id desc limit ?,?",
	    		new BeanListHandler(Content.class), pos, len);
	    
	    return list;
	}
	
	@Override
	public int count() throws SQLException 
	{
		Long count = (Long)runner.query(
				"select count(*) from t_project_graphics_content", 
	    		new ScalarHandler(1));
		
		return count.intValue();
	}
}
